@extends('admin.frame_layout')
<?php $top_selected = "模式管理";$page_menu = "会员升级设置" ?>
@section('content')
    <div class="formbody">
        <div class="formtitle"><span>会员升级设置</span></div>
        <form action="{{route('admin.vip.config.save',['id'=>empty($my_vip_award)?0:$my_vip_award->id])}}" method="post" id="form">
            {!! csrf_field() !!}
            <ul class="forminfo">
                <li>
                    <label class="lable">默认级别</label>
                    <select name="vip" id="vip">
                        <option value="0">新会员级别</option>
                        @foreach($vip_awards as $vip_award)
                            <option value="{{$vip_award->vip}}"
                                    {{isset($my_vip_award)?($my_vip_award->vip == $vip_award->vip ? "selected" : ""):""}}>
                            {{uVipStr($vip_award->vip)}}</option>
                        @endforeach
                    </select>
                    <i for="vip_id">请选择要升级的等级</i>
                </li>

                {!! inputText("会员级别名称", "name", "text",isset($my_vip_award)?("$my_vip_award->name"):(""), "请输入会员名称！") !!}

                {!! inputText("会员奖励", "award", "text",isset($my_vip_award)?("$my_vip_award->award"):(""), "请输入会员奖励！") !!}

                <li>
                    <label class="lable">&nbsp;</label>
                    <input type="submit" class="btn" value="确认保存"/>
                </li>
            </ul>
        </form>
    </div>
@endsection
@section('footer')
    <script>
        $("#form").validate({
            rules: {
                vip: "required",
                name: "required",
                award: "required"
            }, errorPlacement: function (error, element) {
                $(element).closest("form").find("i[for='" + element.attr("id") + "']").html(error);
            },
            submitHandler: function (form) {
                $(form).ajaxSubmit({
                    dataType: "json",
                    type: "post",
                    success: function (data) {
                        if (data.code == 0) {
                            toastr["success"](data.msg);
                            setInterval(function () {
                                window.location.href="{{route('admin.vip.config')}}";
                            }, 2000);
                        } else {
                            toastr["error"](data.msg);
                        }
                    }
                });
            }
        });
    </script>
@endsection
